#ifndef BASE_SHA1DIGEST_H_
#define BASE_SHA1DIGEST_H_

#include "messagedigest.h"
#include "sha1.h"

namespace base {

	// A simple wrapper for our SHA-1 implementation.
	class Sha1Digest : public MessageDigest {
	public:
		enum { kSize = SHA1_DIGEST_SIZE };
		Sha1Digest() {
			SHA1Init(&ctx_);
		}
		virtual size_t Size() const {
			return kSize;
		}
		virtual void Update(const void* buf, size_t len) {
			SHA1Update(&ctx_, static_cast<const uint8*>(buf), len);
		}
		virtual size_t Finish(void* buf, size_t len) {
			if (len < kSize) {
				return 0;
			}
			SHA1Final(&ctx_, static_cast<uint8*>(buf));
			SHA1Init(&ctx_);  // Reset for next use.
			return kSize;
		}

	private:
		SHA1_CTX ctx_;
	};

}  // namespace base

#endif  // BASE_SHA1DIGEST_H_
